﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ModelPredictPro.General.IO {
    public static class FileReader {
        /// <summary>
        /// 逐行返回指定文件的所有行（实行延时加载，可读取超大文件）
        /// </summary>
        /// <returns>返回公开枚举器，应用 foreach 语句访问</returns>
        public static System.Collections.IEnumerable ReadAllLines(string fileName) {
            string line = null;
            using (StreamReader reader = new StreamReader(fileName)) {
                while ((line = reader.ReadLine()) != null) {
                    yield return line;
                }
            }
        }
        /// <summary>
        /// 返回指定文件包含的文本行数
        /// </summary>
        public static int GetLineCount(string fileName) {
            int rst = 0;
            foreach (string line in ReadAllLines(fileName)) {
                rst++;
            }
            return rst;
        }
    }
}
